import socket

addr_port_set = set()


def handle_info(info, addr):
    pass


def execute_demand(info, addr):
    pass

# info 为byte
def send_message(info, addr):
    pass

# 1. 我是要测试
if __name__ == '__main__':
    s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    s.bind((socket.gethostbyname(socket.gethostname()), 8000))
    print(socket.gethostbyname(socket.gethostname()))

    while True:
        data, addr = s.recvfrom(1024)
        addr_port_set.add('{}:{}'.format(addr[0], addr[1]))

        # handle_info(data, addr)
        tmp_list = list(addr_port_set)
        tmp_list.remove('{}:{}'.format(addr[0], addr[1]))
        s.sendto(tmp_list.__str__().encode(), addr)
        print(data.decode('utf-8'), addr)